package com.bruce.ai.controller;

import com.bruce.ai.service.ChatService;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.time.LocalDateTime;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY;


/**
 * @author bruce.shangguan
 * @version 1.0
 * @description:
 */
@RestController
@CrossOrigin
public class OpenAiController  {

    @Resource
    private ChatService chatService ;


    @CrossOrigin
    @GetMapping(value = "/ai/generateStreamAsString", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> generateStreamAsString(@RequestParam(value = "message", defaultValue = "讲个笑话") String message) {
        return chatService.generateStreamAsString(message) ;
    }


    @CrossOrigin
    @GetMapping("/loadJsonData")
    public boolean loadJsonData() {
        return chatService.loadJsonData() ;
    }

    @CrossOrigin
    @GetMapping("/loadPdfData")
    public boolean loadPdfData() {
        return chatService.loadPdfData() ;
    }

}
